 package me.dan.alibabasdk.trade;

import java.util.Map;

import me.dan.alibabasdk.client.DefaultAuthorizationTokenRepository;
import me.dan.alibabasdk.entity.ResponseEntity;
import me.dan.alibabasdk.entity.client.AuthorizationToken;
import me.dan.alibabasdk.entity.trade.product.AlibabaProductGetSellerProductResult;
import me.dan.alibabasdk.infrastructure.GenericAPIPlot;
import me.dan.alibabasdk.infrastructure.HttpMethod;
import me.dan.alibabasdk.infrastructure.Protocol;
import me.dan.alibabasdk.infrastructure.SessionType;
import me.dan.alibabasdk.infrastructure.UriSchema;
import me.dan.alibabasdk.param.trade.ParamsOfProductDetailOnSellerView;
import me.dan.alibabasdk.param.trade.ParamsOfProductListOnSellerView;
import me.dan.alibabasdk.util.RequestParamModelToMap;

public class ProductSellerViewAPIPlot extends GenericAPIPlot{

    /*
     * 
     */
    private void init() {
        this.getRequestPolicy().setRequestBodyCharset("UTF-8");
        this.getRequestPolicy().setHttpMethod(HttpMethod.POST);
        this.getRequestPolicy().setSessionType(SessionType.Product);
        this.getRequestPolicy().setUriSchema(UriSchema.https);
        this.getRequestPolicy().getApi().setApiRoot("openapi");
        this.getRequestPolicy().getApi().setApiNamespace("com.alibaba.product");
        this.getRequestPolicy().getApi().setApiVersion("1");
        this.getRequestPolicy().setRequestProtocol(Protocol.param2);
        this.getRequestPolicy().setValidateSignatureRequired(true);
        this.setTokenRepository(new DefaultAuthorizationTokenRepository());
    }

    public ProductSellerViewAPIPlot() {

        super();
        init();
    }

    /**
     * @Title: OrderListOnSellerViewRetrieve
     * @Description: TODO
     * @param token
     * @param param
     * @return
     * @return ResponseEntity<AlibabaTradeGetSellerOrderListResult>
     * @throws
     * 
     */
    public ResponseEntity<AlibabaProductGetSellerProductResult> productListOnSellerViewRetrieve(AuthorizationToken token,
        ParamsOfProductListOnSellerView param) {

        this.getRequestPolicy().setClientId(token.getClientId());
        this.getRequestPolicy().setClientSecret(token.getClientSecret());
        this.getRequestPolicy().setAccessTokenOrPreAuthCode(token.getAccess_token());
        this.getRequestPolicy().setValidateSignatureRequired(true);
        this.getRequestPolicy().getApi().setApiName("alibaba.product.list.get");
        this.getRequestPolicy().setRequestProtocol(Protocol.param2);

        ResponseEntity<AlibabaProductGetSellerProductResult> result = null;

        Map<String, Object> mappedParam = RequestParamModelToMap.ConvertRequestParamModelToMap(param);
        this.setParams(mappedParam);
        this.setResultType(param.getResponseClass());

        try {
            result = this.getInvokeClient().request(this,
                    this.getInvokeClient().getSerializerProvider().getSerializers(),
                    this.getInvokeClient().getSerializerProvider().getDeSerializers());

        } catch (Exception e) {

            e.printStackTrace();
        }

        return result;
    }

    public ResponseEntity<AlibabaProductGetSellerProductResult> productDetailOnSellerViewRetrieve(AuthorizationToken token,
        ParamsOfProductDetailOnSellerView param) {
        this.getRequestPolicy().setClientId(token.getClientId());
        this.getRequestPolicy().setClientSecret(token.getClientSecret());
        this.getRequestPolicy().setAccessTokenOrPreAuthCode(token.getAccess_token());
        this.getRequestPolicy().setValidateSignatureRequired(true);
        this.getRequestPolicy().getApi().setApiName("alibaba.product.getByIdList");
        this.getRequestPolicy().setRequestProtocol(Protocol.param2);

        ResponseEntity<AlibabaProductGetSellerProductResult> result = null;

        Map<String, Object> mappedParam = RequestParamModelToMap.ConvertRequestParamModelToMap(param);
        this.setParams(mappedParam);
        this.setResultType(param.getResponseClass());

        try {
            result = this.getInvokeClient().request(this,
                    this.getInvokeClient().getSerializerProvider().getSerializers(),
                    this.getInvokeClient().getSerializerProvider().getDeSerializers());

        } catch (Exception e) {

            e.printStackTrace();
        }

        return result;

    }
}
